package com.atguigu.gulimall.product.dao;

import java.util.List;

import com.atguigu.gulimall.product.entity.SkuSaleAttrValueEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.atguigu.gulimall.product.vo.SkuItemSaleAttrVo;
/**
 * sku销售属性&值
 * 
 * @author leifengyang
 * @email leifengyang@gmail.com
 * @date 2019-10-01 21:08:49
 */
@Mapper
public interface SkuSaleAttrValueDao extends BaseMapper<SkuSaleAttrValueEntity> {
    @Select("SELECT ssav.attr_id attr_id,ssav.attr_name attr_name,"
            + "ssav.attr_value,group_concat( DISTINCT info.sku_id ) sku_ids"
            + "FROM pms_sku_info info LEFT JOIN pms_sku_sale_attr_value ssav ON"
            + "ssav.sku_id = info.sku_id WHERE info.spu_id = #{spuId}"
            + "GROUP BY ssav.attr_id, ssav.attr_name, ssav.attr_value")
    List<SkuItemSaleAttrVo> getSaleAttrBySpuId(@Param("spuId") Long spuId);

    @Select("SELECT CONCAT( attr_name, '：', attr_value ) FROM pms_sku_sale_attr_value WHERE sku_id = #{skuId}")
    List<String> getSkuSaleAttrValuesAsStringList(@Param("skuId") Long skuId);

}
